package com.xy.job.admin.common.config

import com.xy.job.admin.core.schedule.Scheduler
import jakarta.validation.Validation
import jakarta.validation.Validator
import org.hibernate.validator.HibernateValidator
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableScheduling


@EnableScheduling
@Configuration
class AppConfig {

    @Bean
    fun validator(): Validator {
        return Validation.byProvider(HibernateValidator::class.java)
            .configure()
            .failFast(true)
            .buildValidatorFactory()
            .validator
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    fun scheduler(): Scheduler {
        return Scheduler(1000, 60)
    }
}